package com.utils;

import android.content.Context;
import android.util.Log;

import com.appsflyer.AFInAppEventParameterName;
import com.appsflyer.AFInAppEventType;
import com.appsflyer.AppsFlyerConversionListener;
import com.appsflyer.AppsFlyerLib;
import com.appsflyer.attribution.AppsFlyerRequestListener;

import org.jetbrains.annotations.NonNls;

import java.util.Map;

public class AppsFlyerUtils {
    private static final String AF_DEV_KEY = "XXXXXX";
    private static Context ct;
    public static void init(Context _ct) {
        ct=_ct;
        AppsFlyerConversionListener conversionListener = new AppsFlyerConversionListener() {
            @Override
            public void onConversionDataSuccess(Map<String, Object> conversionData) {}

            @Override
            public void onConversionDataFail(String errorMessage) {}

            @Override
            public void onAppOpenAttribution(Map<String, String> conversionData) {}

            @Override
            public void onAttributionFailure(String errorMessage) {}
        };
        AppsFlyerLib.getInstance().init(AF_DEV_KEY, conversionListener, ct);
        AppsFlyerLib.getInstance().start(ct);
        AppsFlyerLib.getInstance().setDebugLog(true);
    }

    public static void trackEvent(Map<String, Object> map) {
        AppsFlyerLib.getInstance().logEvent(ct, AFInAppEventType.PURCHASE, map, new AppsFlyerRequestListener() {
            @Override
            public void onSuccess() {
                Log.d("log >>",">>> afEvent report success <<<");
            }
            @Override
            public void onError(int i, @NonNls String s) {
                Log.d("log >>",">>> afEvent report failed <<<  " + s);
            }
        });
    }
    public static void trackEvent(String event, Map<String, Object> map) {
        AppsFlyerLib.getInstance().logEvent(ct, event.toLowerCase(), map, new AppsFlyerRequestListener() {
            @Override
            public void onSuccess() {
                Log.d("log >> ","流程检测 >> ------12 >>  AF事件上报成功");
            }

            @Override
            public void onError(int i, @NonNls String s) {
                Log.d("log >>","流程检测 >> ------12 >>  AF事件上报失败"+s);
            }
        });
    }
}
